import request from "./fetch";
import { getToken } from "./auth";

//Insterceptors：请求拦截器
request.insterceptors.request.use((config) => {
  const token = getToken();
  if (!token) return config;
  config.headers = {
    ...config.headers,
    Authorization: `Bearer ${token}`,
  };
  return config;
});


//Insterceptors：响应拦截器
request.insterceptors.response.use((response) => {
  if (response.status === 401) {
    console.log("token失效，请重新登录");
  }

  return response;
});
